package com.entor.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.entor.model.Dues;
import com.entor.model.Msg;
import com.entor.model.Partymember;
import com.entor.service.BaseServiceI;
import com.entor.service.DuesServiceI;
import com.entor.util.SendUtil;


@Controller
@RequestMapping("/dc")
public class DuesController extends BaseController<Dues>{

	
	@Resource(name="duesServiceI")
	private DuesServiceI dc;
	
	
	@Resource(name="partymemberService")
	private BaseServiceI<Partymember> pm;
	
	
	@RequestMapping("/index")
	public String index(){
		return "/dues/index";
	}
	
	@Override
	public List<Dues> find(Dues d){
		
		return dc.find(d);
	}
	
	@RequestMapping("/pay")
	@ResponseBody
	public Msg pay(Dues d){
		
		
		return dc.edit(d);
	}
	
	
	@RequestMapping("/addpay")
	public String addpay(HttpServletRequest req) throws UnsupportedEncodingException{
		
		String vals = req.getParameter("vals");
		
		if(vals!=null){
			
			vals = new String(vals.getBytes("iso-8859-1"),"utf-8");//�������봦��
			Dues d = JSON.parseObject(vals,Dues.class);
			req.setAttribute("db", d);
		}
		
		return "/dues/addpay";
	}
	
	@RequestMapping("/add")
	public String add(HttpServletRequest req){
		
		
		
		return "/dues/addOredit";
		
		
	}
	
	
	
	@Override
	public Msg insert(Dues d,
			@RequestParam(required=false,value="file") MultipartFile[] files){
		
		Msg m = new Msg("新增失败",false);
		int id = d.getId();
		
		m = dc.insert(d);
		
		int grade = d.getId();
		Partymember p = new Partymember();
		
		p.setId(id);
		p.setGrade(grade+"");
		m =  pm.edit(p);
		
		
		
		
		
		return m;
		
	}
	
	
	
	@RequestMapping("/call/{id}.coc")
	@ResponseBody
	public Msg call(@PathVariable(value="id") Integer id){
		
		Partymember p =new Partymember(); 
		p.setGrade(id+"");
		p = pm.get(p);
		Msg m = dc.send(p);
		return m;
		
	}
	
	@RequestMapping("/batchDel")
	@ResponseBody
	public Msg batchDel(String ids){
		
	
		return dc.batchRemove(ids);
	}
	
	
	
	
	
	
	
	
	
	
	
}

















